package com.example.springboot.controller.browser;

import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.OperatingSystem;
import eu.bitwalker.useragentutils.UserAgent;
import eu.bitwalker.useragentutils.Version;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/10/8 11:15
 */
@RestController
@RequestMapping("/browser")
@Slf4j
public class BrowserInformation {
    @GetMapping("/info")
    public void getBrowser(HttpServletRequest request) {
        String ua = request.getHeader("User-Agent");
        log.info("******************************");
        log.info("操作系统及浏览器信息：" + ua);
        UserAgent userAgent = UserAgent.parseUserAgentString(ua);
        // 浏览器信息
        Browser browser = userAgent.getBrowser();
        log.info("【浏览器信息-{}】", browser);
        // 系统信息
        OperatingSystem operatingSystem = userAgent.getOperatingSystem();
        log.info("【用户操作系统信息-{}】", operatingSystem);
        // 系统名称
        String name = operatingSystem.getName();
        log.info("【系统名称-{}】", name);
        String browserName = browser.getName();
        log.info("【浏览器名称-{}】", browserName);
    }
}
